package com.wdy.interceptor;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.wdy.po.User;

@SuppressWarnings({"serial", "unchecked", "unused"})
public class AuthInterceptor extends AbstractInterceptor {
	
	private static final Log log = LogFactory.getLog(AuthInterceptor.class);
	protected static Map<String, String> roleMethodMap = new HashMap<String, String>();

	static {
		if (roleMethodMap.size() <= 0) {
			roleMethodMap.put("list", "view");
			roleMethodMap.put("store", "edit");
			roleMethodMap.put("remove", "remove");
		}
	}
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		// TODO Auto-generated method stub
		Map session = invocation.getInvocationContext().getSession();
		String method = invocation.getProxy().getActionName();
		User user = null;
		user = (User)session.get("login");
		if(null != user){
			String privilege = user.getPrivilege();
			if("0".equals(privilege)){
				invocation.invoke();
				return "admin";
			}else if("1".equals(privilege)){
				return "common";
			}
		}
		return "illegal";
	}

}
